from app.alg import Graph

# 楼梯分布情况
# | - - - - - - | - | - - - - |  - - - - - | 
# 东<--->西
# 教室门朝向西，假设不从后门进入，因此增加东边楼梯的节点，西边楼梯直接表示为教室节点
# level0：入口层， st1~st6 六个入口
# ??x 未编号教室
# |ab 楼梯 a为楼梯编号 0~6 b为楼层
# st? 地面层楼梯入口
# --- 没有教室
level0 = ['---', '---', '---', 'st1', '01x', 'st2', 'st3', '02x', 'st4', '03x', '04x', 'st5', '05x', 'st6', '---', '---', '---']
level1 = ['|01', '101', '10x', '105', '106', '107']
level2 = ['|02', '201', '203', '206', '207', '208', '211', '215', '216', '217']
level3 = ['|03', '301', '303', '306', '307', '308', '311', '312', '314', '315', '316', '318', '31x', '320']
level4 = ['|04', '401', '403', '406', '407', '408', '411', '412', '414', '415', '416', '418', '419', '421', '422', '425', '426']
level5 = ['|05', '50x', '501', '|15', '502', '503', '506', '507', '509', '510', '511', '513', '514', '516', '517', '520', '521']
level6 = ['---', '---', '---', '---', '---', '---', '|36', '601', '60x', '602', '603', '605', '606', '608', '609', '612', '613']
level7 = ['---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '---', '|57', '701', '|67', '703', '706', '707']

nodes = [level0, level1, level2, level3, level4, level5, level6, level7]
# graph.append(level1, level2)


# 教室间距
span_distance = 10
# 楼层高度
height = 4


def initGraph():
    graph = Graph()

    for l in nodes:
        for v in l:
            graph.addNode(v)

    # print(graph.node)
    # print(graph.vlookup)

    # 每层连边
    for l in nodes:
        for i in range(1, len(l)):
            if l[i-1]!='---' and l[i]!='---':
                graph.addEdge(l[i-1], l[i], span_distance, 'walk')

    # 上下连边
    # st1 105相连
    # st2 107相连
    # st3 211相连
    # st4 上楼 312
    # st5 318相连
    # st6 320相连
    graph.addEdge('st1', '105', 0)
    graph.addEdge('st2', '107', 0)
    graph.addEdge('st3', '211', height/2, 'up')
    graph.addEdge('st4', '312', height, 'up')
    graph.addEdge('st5', '318', 0)
    graph.addEdge('st6', '320', 0)

    # 楼梯
    graph.addEdge('|01', '|02', height, 'up')
    graph.addEdge('|02', '|03', height, 'up')
    graph.addEdge('|03', '|04', height, 'up')
    graph.addEdge('|04', '|05', height, 'up')

    graph.addEdge('105', '206', height, 'up')
    graph.addEdge('206', '306', height, 'up')
    graph.addEdge('306', '406', height, 'up')
    graph.addEdge('406', '|15', height, 'up')

    graph.addEdge('107', '208', height, 'up')
    graph.addEdge('208', '308', height, 'up')
    graph.addEdge('308', '408', height, 'up')
    graph.addEdge('408', '503', height, 'up')

    graph.addEdge('211', '311', height, 'up')
    graph.addEdge('311', '411', height, 'up')
    graph.addEdge('411', '506', height, 'up')
    graph.addEdge('506', '|36', height, 'up')

    graph.addEdge('312', '412', height, 'up')
    graph.addEdge('412', '507', height, 'up')
    graph.addEdge('507', '601', height, 'up')

    graph.addEdge('318', '418', height, 'up')
    graph.addEdge('418', '513', height, 'up')
    graph.addEdge('513', '605', height, 'up')
    graph.addEdge('605', '|57', height, 'up')

    graph.addEdge('320', '421', height, 'up')
    graph.addEdge('421', '516', height, 'up')
    graph.addEdge('516', '608', height, 'up')
    graph.addEdge('608', '|67', height, 'up')

    # print(graph.g)

    # 北楼
    # st3 443 地面层相连
    # st5 434 地面层相连
    Nlevel4 = ['442', '443', '437', '434', '433']
    Nlevel5 = ['538', '537', '532', '529', '528']

    for v in Nlevel4:
        graph.addNode(v)

    for v in Nlevel5:
        graph.addNode(v)

    # 连边
    for i in range(1, len(Nlevel4)):
        graph.addEdge(Nlevel4[i-1], Nlevel4[i], span_distance*3, 'walk')

    for i in range(1, len(Nlevel5)):
        graph.addEdge(Nlevel5[i-1], Nlevel5[i], span_distance*3, 'walk')

    # 上下楼梯
    graph.addEdge('st3', '443', height, 'up')
    graph.addEdge('st5', '434', height, 'up')    

    graph.addEdge('443', '537', height, 'up')
    graph.addEdge('434', '529', height, 'up')

    # 忽略南北楼之间的连接
    # 需要实地考察 哪几间是相邻的
    return graph 